

import axios from 'axios'
import Vue from 'vue';
import router from './../router';
import store from './../store';
import {  Message } from 'element-ui';
// axios响应拦截器|
// axios.defaults.baseURL = 'http://localhost/box/public/index.php'
axios.defaults.baseURL = '/admin'
axios.defaults.withCredentials = true
const b = axios.crossDomain = true;
axios.interceptors.response.use(function (response,error) {
	if (response.data.code === 401) {
		// 改变登录态 没有登录时跳到登录页
		localStorage.setItem("login",0)
		store.commit('login',false);
		router.push('/login');
	} else if (response.data.code === 403) {
		// 没有权限时跳转到首页
    Message.error(response.data.msg);
		setTimeout(function(){
			router.push('/index');
		},1000)
	} else if (response.data.code !== 200) {
    	Message.error(response.data.msg);
	}
	return response;
  }, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});

axios.interceptors.request.use(config => {

	config.headers.Accept = 'application/vnd.api.v1+json';
	return config;
})
export default axios
